<?php
/**
 * 扫码支付
 */
include_once dirname(dirname(__DIR__)) . '/vendor/autoload.php';

$tencent = \KukePay\PayInterface::tencent([
    'app_id' => '',
    'secret'=>''
]);

function getUri()
{
    $uri = $_SERVER['REQUEST_URI'];

    $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ?

        "https://": "http://";



    $url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

    return $url;//输出完整的url
}

$oauth = $tencent->oauth;

$uri = $oauth->setScopes('snsapi_userinfo')->redirect(getUri());


if (empty($_GET['code'])){
    header('location:'.$uri);die;
}

echo '<pre>';

var_dump($oauth->getUserInfo($_GET['code']));